package com.weitu.observation.statisticsAnalysis.controller;

import com.weitu.observation.statisticsAnalysis.entity.StatisticAnalysisType;
import com.weitu.observation.statisticsAnalysis.entity.StatisticsAnalysis;
import com.weitu.observation.statisticsAnalysis.service.StatisticAnalysisService;
import com.weitu.paging.DataGridPagination;
import com.weitu.plugin.PageView;
import com.weitu.util.TableTreeNodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.weitu.base.controller.BaseController;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by smp on 2017/4/14.
 */
@Controller
@RequestMapping(value = "observation/statisticsAnalysis")
public class StatisticAnalysisController extends BaseController {

    private static final String MODULE_BATH_PATH= BASE_JSP_PATH+"observation/statisticsAnalysis";

    private final StatisticAnalysisService statisticAnalysisService;

    @Autowired
    public StatisticAnalysisController(StatisticAnalysisService statisticAnalysisService){
        this.statisticAnalysisService=statisticAnalysisService;
    }
    /**
     * 按观察单位
     * @return
     */
    @RequestMapping(value = "/unitList",method = RequestMethod.GET)
    public String unitList(){
        return MODULE_BATH_PATH+"/unitList";
    }
    /**
     * 观察者部门统计
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/unitList",method = RequestMethod.POST)
    public List<Map<String,Object>> unitListAjax(HttpServletRequest request){
        Map<String,Object> paramMap=new HashMap<String, Object>();
        putParametersIntoMap(paramMap);
        List<Map<String,Object>> maps=this.statisticAnalysisService.queryStatisticsAnalysisList(paramMap);
        List<Map<String,Object>> mapList= TableTreeNodeUtil.getFatherNode(maps);
        return mapList;
    }

    /**
     * 按不安全行为
     * @return
     */
    @RequestMapping(value = "/actList",method = RequestMethod.GET)
    public String actList(){
        return MODULE_BATH_PATH+"/actList";
    }

    /**
     * 不安全行为统计
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/actList",method = RequestMethod.POST)
    public List<StatisticAnalysisType> actListAjax(HttpServletRequest request){
        Map<String,Object> paramMap=new HashMap<String, Object>();
        putParametersIntoMap(paramMap);
        return this.statisticAnalysisService.queryStatisticsAnalysisByDictionaryType(paramMap);
    }

    /**
     * 按间接原因
     * @return
     */
    @RequestMapping(value = "/causeList",method = RequestMethod.GET)
    public String causeList(){
        return MODULE_BATH_PATH+"/causeList";
    }

    /**
     * 按不安全状态
     * @return
     */
    @RequestMapping(value = "/stateList",method = RequestMethod.GET)
    public String stateList(){
        return MODULE_BATH_PATH+"/stateList";
    }

    /**
     * 按被观察单位
     * @return
     */
    @RequestMapping(value = "/unitBeanList",method = RequestMethod.GET)
    public String unitBeanList(){
        return MODULE_BATH_PATH+"/unitBeanList";
    }
    @RequestMapping(value = "/contractor",method = RequestMethod.GET)
    public String contractor(){
            return MODULE_BATH_PATH+"/contractor";
    }
    /**
     * 按被观察单位统计列表
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/unitBeanList",method = RequestMethod.POST)
    public List<Map<String,Object>> unitBeanListAjax(HttpServletRequest request){
        Map<String,Object> paramMap=new HashMap<String,Object>();
        putParametersIntoMap(paramMap);
        List<Map<String,Object>> maps= this.statisticAnalysisService.queryBeanStatisticsAnalysis(paramMap);
        List<Map<String,Object>> mapList= TableTreeNodeUtil.getFatherNode(maps);
        return mapList;
    }

    /**
     * 查询被观察承包商列表
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/contractorBeanList",method = RequestMethod.POST)
    public Object contractorBeanListAjax(HttpServletRequest request){
        Map<String,Object> paramMap=new HashMap<String,Object>();
        putParametersIntoMap(paramMap);
        int count=this.statisticAnalysisService.queryContractorCount(paramMap);
        DataGridPagination dataGridPagination=DataGridPagination.getInstance(request,count);

        PageView pageView=dataGridPagination.getPageView();
        paramMap.put("pageView",pageView);

        List<StatisticsAnalysis> dataList=this.statisticAnalysisService.queryContractorStatisticsAnalysis(paramMap);
        return dataGridPagination.flushDataGridData(dataList);
    }
}
